﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using GalleryCommon;

namespace GalleryLogic
{
    public static class PictureLogic
    {

        public static bool AddNewPicture(string Name, long AlbumID, byte[] Picture)
        {
            GalleryDataProvider.PictureDataProvider.AddNewPicture(Name, DateTime.Now, AlbumID, "Test", Picture);

            return true;
        }
        public static bool ProvidePicture(User user, out List<Picture> Pictures, int LastPicNo)
        {
            GalleryDataProvider.PictureDataProvider.GivePicture(user.ActiveAlbumID, out Pictures, LastPicNo);
            
            return true;
       
        }

        public static bool ProvidePictureByID(long PicID, out Picture Picture)
        {
            GalleryDataProvider.PictureDataProvider.GivePictureByPicID(PicID, out Picture);

            return true;

        }


        public static bool AddNewPublicLink(long PicID, out string Link)
        {
            GenerateLink(PicID, out Link);
            GalleryDataProvider.PictureDataProvider.InsertPublicLink(PicID, Link);

            return true;
        }

        public static bool ProvidePublicPicture(string PicID, out Picture Picture)
        {
            GalleryDataProvider.PictureDataProvider.GivePictureByPublicID(PicID, out Picture);

            return true;

        }

        public static bool GenerateLink(long PicID, out string Link)
        {
            string link = Guid.NewGuid().ToString();

            for (int i = 0; i < link.Length; ++i)
            {
                if (link[i] == '-')
                {
                    link = link.Remove(i, 1);
                }
            }

            Link = link;

            return true;
        }
    }
}
